/**
 * Created by yangfakuan on 2018/10/19.
 */
(function () {
    var e;
    var t;
    var a;
    var o;
    var i = function (i) {
        var l = i.accountInfoArr || [];
        var d = "";
        var h = i.queryCond;
        var v = i.optType;
        var p = i.desc || rss_new.risk_control_low;
        var f = i.userAccount;
        var g = i.opType;
        var _ = i.operType;
        var y = i.reqType;
        o = i.isLogin;
        var m = i.checkOperType;
        var A = i.chkAuthFn;
        var C = i.siteID;
        e = l[0].userAccount;
        t = l[0].accountType;
        a = getExpressPhone(e);
        d += '<p class="inptips2">' + p + "</p>";
        d += '<div style="width:100%;height:16px;"></div>';
        d += '<div class="line-EMUI5" style="margin-bottom:8px;">';
        d += '<div id="accountDiv" >' + a + "</div>";
        d += "</div>";
        d += '<div class="dinput-UI5 authCodeDivCom" id="authCodeDiv">';
        d += '<div id="getAuthCodeBtn" class="getAuthbtn"  intervaltime="60"><a class="a-EMUI5 getAuthText">' + rss_new.uc_common_get_authcode + '</a><div id="authCodeError" class="left"></div></div>';
        d += '<div id="authCodeInput" class="input-div  clearfloat"><input type="tel"  id="oldAuthCode" ><p id="oldAuthCode_error_info"></p></div>';
        d += "</div>";
        d += '<div id="msg_error_auth" class="error-tips-EMUI5 " style=""></div>';
        d += r(l);
        var T = rss.enter_authcode_title;
        var D = {
            title: rss_new.vertify_identity, uc: true, btnRight: {
                text: rss_new.common_ok, fn: function () {
                    var a = this;
                    var o = $("#accountDiv span").text().trim();
                    var n = $("#oldAuthCode")[0];
                    if (!validator(n, true)) {
                        return false
                    }
                    var r = $("#oldAuthCode").val();
                    if (typeof A == "function") {
                        var c = {authCode: r, authUserAccount: e, authAccountType: t, opType: g};
                        A(c, function () {
                            a.hide()
                        })
                    } else {
                        chekAuthParams = {
                            authAccountType: t,
                            authUserAccount: e,
                            authCode: r,
                            operType: m,
                            siteID: C,
                            errorBorderDiv: $("#authCodeDiv"),
                            errorTipEl: $("#msg_error_auth"),
                            callbackFn: function (o) {
                                a.hide();
                                if (g == "6") {
                                    var n = {
                                        userAccount: h,
                                        userAccountCode: e,
                                        accountTypeCode: t,
                                        authCode: r,
                                        callbackFn: i.callbackFn,
                                        opType: i.opType,
                                        verifyID: "1",
                                        verifyself: a
                                    };
                                    updatePWDDialog(n)
                                } else {
                                    i.callbackFn(o)
                                }
                            }
                        };
                        s(chekAuthParams)
                    }
                }
            }, btnLeft: {
                text: i.lBtnTxt, fn: function () {
                    if (typeof CLOUDAUTH != "undefined") {
                        window.history.back()
                    }
                }
            }, html: d, dialogStyle: localInfo.msgDialogStyle, beforeAction: function () {
                u($("#oldAuthCode"), "#msg_error_auth", "#authCodeDiv");
                n(e, t);
                var a = this;
                a.disabled();
                $("#oldAuthCode").on("textchange", function () {
                    $("#msg_error_auth").html("");
                    if ($("#oldAuthCode").val().trim() != "") {
                        a.enable();
                        return false
                    } else {
                        a.disabled()
                    }
                });
                $("#getAuthCodeBtn").on("click", function (a) {
                    $("#authCodeDiv").removeClass("input-error-EMUI5");
                    $("#msg_error_auth").html("");
                    if ($("#getAuthCodeBtn").attr("disabled")) {
                        return false
                    }
                    var o = $("#accountDiv")[0];
                    if (!validator(o, true)) {
                        return false
                    }
                    var i = {phoneOrEmail: e, authCodebtn: $("#getAuthCodeBtn")};
                    if (localInfo.userID) {
                        i.userID = localInfo.userID
                    }
                    i.siteID = C;
                    i.type = v;
                    i.reqType = y;
                    if (g == 1 || g == 4) {
                        i.accountType = getAccountType(h)
                    } else {
                        i.accountType = t
                    }
                    i.errorDiv = $("#authCodeDiv");
                    i.account = h;
                    i.errorTip = $("#msg_error_auth");
                    i.operType = _;
                    i.leftPix = "-260px";
                    i.rightPix = "-260px";
                    i.bottom = "20px";
                    getAuthCode(i)
                });
                $("#otherAuth").click(function () {
                    a.hide();
                    var t = [];
                    $.each(l, function (a, o) {
                        if (o.userAccount != e) t.push(o)
                    });
                    c(t, getAppealChangesLinkDiv(l), function (e, t) {
                        a.show();
                        n(e, t)
                    })
                })
            }
        };
        localInfo.authDialog = $("<div>").Dialog(D).Dialog("show")
    };

    function n(o, i) {
        if (!o)return;
        e = o;
        t = i;
        a = getExpressPhone(e);
        $("#accountDiv").text(a);
        if (e.indexOf("@") != -1) {
            $("#oldAuthCode").attr("placeholder", rss_new.registerbyphone_js_emailcodelength)
        } else {
            $("#oldAuthCode").attr("placeholder", rss_new.registerbyphone_js_codelength)
        }
    }

    function r(e) {
        if (e.length <= 1) {
            return '<div class="center marginT16">' + getAppealChangesLinkDiv(e) + "</div>"
        } else {
            return '<div id="otherAuth" class="center marginT16"><a href="javascript:void(0)" class="a-EMUI5">' + rss_new.appeal_select_other_way + "</a></div>"
        }
    }

    function c(e, t, a, o) {
        var i = "";
        var n = '<div class="uc-line" style="padding:0"><div></div></div>';
        var r = {
            title: rss_new.resetPwd_choose_other_verify_way,
            btnRight: {
                text: rss_new.uc_common_cancel, fn: function () {
                    this.hide();
                    a()
                }
            },
            cancelFn: function () {
                this.hide();
                a()
            },
            dialogStyle: o || localInfo.msgDialogStyle,
            beforeAction: function () {
                var e = this;
                var e = this;
                addItemActive($(".dialog-line"), "dialog-line-active", "dialog-line-disabled");
                addItemActive($(".a-EMUI5"), "a-EMUI5-active");
                $(".dialog-line").click(function () {
                    e.hide();
                    var t = $(this).data("useraccount");
                    var o = $(this).data("accounttype");
                    a(t, o)
                })
            }
        };
        $.each(e, function (e, t) {
            i += '<div class="dialog-line" data-useraccount="' + t.userAccount + '" data-accounttype="' + t.accountType + '">' + '<span class="item-name item-left l"><a class="a-EMUI5">' + rss_new.auth_dialog_send_to.format(t.userAccount) + "</a></span>" + '<div class="item-right"><span class="info-value item-forward" ></span></div>' + "</div>" + n
        });
        i += "<div class='center marginT16'>" + t + "</a></div>";
        r.html = i;
        $("<div>").Dialog(r).Dialog("show");
        $(".global_dialog_confirm_content").css("padding-top", "0px")
    }

    function u(e, t, a) {
        e.validator("bind", {
            type: ["require", "length", "int"],
            trim: true,
            validOnChange: false,
            max: 8,
            min: 4,
            errorFunction: function (e, o) {
                $(a).addClass("input-error-EMUI5");
                switch (o.type) {
                    case"require":
                        $(t).html(rss_new.common_js_inputcode);
                        break;
                    case"length":
                    case"int":
                        $(t).html(rss_new.common_wrong_authcode);
                        break
                }
            },
            successFunction: function (e, t) {
                $(a).removeClass("input-error-EMUI5")
            },
            reInputFunction: function () {
                $(t).html("");
                $(a).removeClass("input-error-EMUI5")
            }
        })
    }

    function s(e) {
        var t = e.callbackFn;
        var a = {
            accountType: e.authAccountType,
            userAccount: e.authUserAccount,
            authCode: e.authCode,
            authOprType: e.authOprType || 3,
            operType: e.operType,
            siteID: e.accountSiteID,
            reqClientType: localInfo.reqClientType
        };
        var i = {"default": rss_new.common_wrong_authcode};
        if (o) {
            casAjaxObj.chkAuthCodeBySession(a, n, r, i)
        } else {
            casAjaxObj.chkAuthCode(a, n, r, i)
        }
        function n() {
            var a = {
                oldAccountType: e.authAccountType,
                oldUserAccount: e.authUserAccount,
                oldAuthCode: e.authCode,
                reqClientType: localInfo.reqClientType
            };
            t(a)
        }

        function r(e) {
            $("#authCodeDiv").addClass("input-error-EMUI5");
            $("#msg_error_auth").html(e)
        }
    }

    i.initAuthInfo = n;
    i.getNoReceiveLink = r;
    i.openOtherAuthDialog = c;
    window.authDialog = i
})();